﻿/*
NAILSUPERSTORE ® COMPANY
 
[HISTORY]
Created By  	: NGUYEN VAN TY
Created Date	: 28/02/2011
Modified By     :
Modified Date   :
Note            :

*/

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using CommonTagTime;
using CommonTagTime.ModelObject;
using CommonTagTime.Business;
namespace CommonTagTime.DataAccess
{
    public class daoCountryAreaCategory
    {
        public daoCountryAreaCategory()
        {

        }
        public CountryAreaCategoryCollection GetByCategoryId(int categoryId)
        {
            clsSQL clsSQL = new clsSQL();
            SqlParameter[] para = new SqlParameter[1];
            SqlDataReader de;
            CountryAreaCategoryCollection items = new CountryAreaCategoryCollection();
            try
            {
                para[0] = new SqlParameter(busCountryAreaCategory.AreaCategoryId, SqlDbType.Int);
                para[0].Value = categoryId;
                de = clsSQL.SPDataReader("CountryAreaCategory_GetByCategoryID", para);
                while (de.Read())
                {
                    CountryAreaCategory item = Load(de);
                    items.Add(item);
                }
                de.Close();
                de.Dispose();
            }
            catch (Exception e)
            {
                clsFile.WriteLog("daoCountryAreaCategory", "GetByCategoryId(int categoryId)", e.ToString());
            }
            finally
            {
                de = null;
                clsSQL.Dispose();
                clsSQL = null;
            }
            return items;
        }
        public CountryAreaCategoryCollection GetByCountryId(int CountryId)
        {
            clsSQL clsSQL = new clsSQL();
            SqlParameter[] para = new SqlParameter[1];
            SqlDataReader de;
            CountryAreaCategoryCollection items = new CountryAreaCategoryCollection();
            try
            {
                para[0] = new SqlParameter(busCountryAreaCategory.CountryID, SqlDbType.Int);
                para[0].Value = CountryId;
                de = clsSQL.SPDataReader("CountryAreaCategory_GetByCountryID", para);
                while (de.Read())
                {
                    CountryAreaCategory item = Load(de);
                    items.Add(item);
                }
                de.Close();
                de.Dispose();
            }
            catch (Exception e)
            {
                clsFile.WriteLog("daoCountryAreaCategory", "GetByCountryId(int CountryId)", e.ToString());
            }
            finally
            {
                de = null;
                clsSQL.Dispose();
                clsSQL = null;
            }
            return items;
        }
        private CountryAreaCategory Load(IDataReader de)
        {
            CountryAreaCategory item = new CountryAreaCategory();
            item.AreaCategoryId = clsConvert.DbToInt("AreaCategoryId", de);
            item.CountryID = clsConvert.DbToInt("CountryID", de);
            item.SortOrder = clsConvert.DbToInt("SortOrder", de);
            return item;
        }
        public bool DeleteByCountryId(int CountryId)
        {
            int result = 0;
            clsSQL clsSQL = new clsSQL();
            SqlParameter[] para = new SqlParameter[1];
            try
            {
                para[0] = new SqlParameter(busCountryAreaCategory.CountryID, SqlDbType.Int);
                para[0].Value = CountryId;
                result = clsSQL.SPExecute("CountryAreaCategory_DeleteByCountryID", para);
            }
            catch (Exception ex)
            {
                clsFile.WriteLog("daoCountryAreaCategory", "DeleteByCountryId(int CountryId)", ex.ToString());
            }
            finally
            {
                clsSQL.Dispose();
                clsSQL = null;
            }
            if (result > 0)
                return true;
            return false;
        }
        public bool Insert(CountryAreaCategory objData)
        {

            int result = 0;
            clsSQL clsSQL = new clsSQL();
            SqlParameter[] para = new SqlParameter[2];
            try
            {
                para[0] = new SqlParameter(busCountryAreaCategory.CountryID, SqlDbType.Int);
                para[0].Value = objData.CountryID;
                para[1] = new SqlParameter(busCountryAreaCategory.AreaCategoryId, SqlDbType.Int);
                para[1].Value = objData.AreaCategoryId;                
                result = clsSQL.SPExecute("CountryAreaCategory_Insert", para);

            }
            catch (Exception ex)
            {
                clsFile.WriteLog("daoCountryAreaCategory", "Insert(CountryAreaCategory objData)", ex.ToString());
            }
            finally
            {
                clsSQL.Dispose();
                clsSQL = null;
            }
            if (result > 0)
                return true;
            return false;
        }

    }
}
